package com.example.myapplication;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private static final String TAG="firstclass";
    TextView myout,advise,bmi1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.firstclass);
        myout=findViewById(R.id.out);
        advise=findViewById(R.id.out1);
        bmi1=findViewById(R.id.out2);
        myout.setText("BMI计算");
        advise.setText("请输入后查看");
        System.out.println("this is system.out.println");

        Log.i("aaaa", "onCreate:");
    }
    public void  click(View v){
        Log.i(TAG,"click:........");
        //获取用户输入
        EditText input1 =findViewById(R.id.input1);
        EditText input2 =findViewById(R.id.input2);
        String inputStr1=input1.getText().toString();
        String inputStr2=input2.getText().toString();
        float x=Float.parseFloat(inputStr1);
        float y=Float.parseFloat(inputStr2);
        float bmi=y/(x*x);
        String str1=String.format("%.2f",bmi);
        bmi1.setText("你的BMI值为："+str1);
        if(bmi<=18.4) {
            myout.setText("偏瘦");
            advise.setText("多吃");
        }
        else if (bmi<=23.9) {
            myout.setText("正常");
            advise.setText("维持正常饮食习惯");
        } else if (bmi<=27.9) {
            myout.setText("过胖");
            advise.setText("少吃，合理安排饮食");
        }else {
            myout.setText("肥胖");
            advise.setText("注意饮食，加强锻炼");
        }
        Log.i(TAG, "click: click:用户输入身高为："+ inputStr1);
        Log.i(TAG, "click: click:用户输入身高为："+ inputStr2);
       // TextView myout=findViewById(R.id.out);
        // myout.setText("Hi "+ inputStr.toUpperCase());


    }

}